const baseUrl = "http://127.0.0.1:7001"
export const createOrder = (data, cb) => {
  return wx.request({
    url: `${baseUrl}/order`,
    method: "POST",
    data,
    header: {
      token: wx.getStorageSync('token'),
    },
    success(data) {
      cb(data)
    },
    fail(error) {
      console.log(error)
    }
  })
}
export const getOrders = (cb, data = {}) => wx.request({
  url: `${baseUrl}/order`,
  method: "GET",
  data,
  header: {
    token: wx.getStorageSync('token'),
  },
  success(res) {
    cb(res)
  },
  fail(error) {
    console.log(error)
  }
})

export const getOrderById = (id, cb) => {
  return wx.request({
    url: `${baseUrl}/order/${id}`,
    method: "GET",
    header: {
      token: wx.getStorageSync('token'),
    },
    success(res) {
      cb(res)
    },
    fail(error) {
      console.log(error)
    }
  })
}
export const getMyOrder = (cb, data = {}) => {
  return wx.request({
    url: `${baseUrl}/myorder`,
    method: "GET",
    data,
    header: {
      token: wx.getStorageSync('token'),
    },
    success(res) {
      cb(res)
    },
    fail(error) {
      console.log(error)
    }
  })
}
//参加剧本
export const joinOrder = ({ id, sex }, cb) => {
  return wx.request({
    url: `${baseUrl}/order/${id}`,
    method: "POST",
    header: {
      token: wx.getStorageSync('token'),
    },
    data: {
      sex
    },
    success(res) {
      cb(res)
    },
    fail(error) {
      console.log(error)
    }
  })
}

export const quitOrder=({ id, sex }, cb)=>{
  return wx.request({
    url: `${baseUrl}/order/${id}`,
    method: "DELETE",
    header: {
      token: wx.getStorageSync('token'),
    },
    data: {
      sex
    },
    success(res) {
      cb(res)
    },
    fail(error) {
      console.log(error)
    }
  })
}